package com.orphan.supplier.controller;

import com.orphan.util.dto.SupplierFreezeDto;
import com.orphan.util.dto.SupplierInfoDto;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SupplierInfoController {
    //放进MQ
    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("supplierInfo")
    public String addTickets(){
      SupplierInfoDto supplierInfoDto =new SupplierInfoDto();
      supplierInfoDto.setId(1);
      supplierInfoDto.setBrand("11");
      supplierInfoDto.setPassword("11234");
      supplierInfoDto.setUsername("2314");
        rabbitTemplate.convertAndSend("supplierExchange","Register",supplierInfoDto);
        return "ok";
    }
    @GetMapping("test")
    public String test(){
        SupplierFreezeDto supplierFreezeDto =new SupplierFreezeDto();
        rabbitTemplate.convertAndSend("supplierExchange","RegisterReturn",supplierFreezeDto);
        return "ok";
    }
    @GetMapping("reg/{username}/{password}/{gender}/{tel}/{brand}")
    public String reg(@PathVariable("username") String username,@PathVariable("password") String password,@PathVariable("gender") String gender,@PathVariable("tel") String tel,@PathVariable("brand") String brand){
        SupplierInfoDto supplierInfoDto =new SupplierInfoDto();

        supplierInfoDto.setBrand(brand);
        supplierInfoDto.setPassword(password);
        supplierInfoDto.setUsername(username);
        supplierInfoDto.setGender(gender);
        supplierInfoDto.setTel(tel);
        rabbitTemplate.convertAndSend("supplierExchange","Register",supplierInfoDto);
        System.out.println(supplierInfoDto);
        return "ok";
    }
}
